package com.xpgk.mvc.statistic.zbStatistic;

import java.util.Date;
import java.util.List;

import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.statistic.dailyTotalStatistic.DailyNursingTotal;
import com.xpgk.mvc.user.User;

public class ZbDailyTotalStatisticController extends BaseController{
	
	
	public  void  index()
	{	
		/*String organids = getCUserOrganIds();
		Organization organ =  Organization.dao.findById(organids);
		setAttr("organ",organ );
		setAttr("organids", organids);*/
		/*Organization organization = Organization.dao.findById(getCUserOrganIds());
		setAttr("organization", organization);*/
		render("zbDailyTotal.html");
	}
	
	public  void  getZbDailyTotal()
	{
		String startdate  = getPara("_query.startdate");
		String lastdate  = getPara("_query.lastdate");
		User user = getCUser();
		String json ="";
		//String stationIds  =  getCUserStationIds();
		
		//String organids = getPara("organIds");
		//Organization organization = Organization.dao.findById(organids);
		splitPage.getQueryParam().put("lastdate", lastdate);
		splitPage.getQueryParam().put("startdate", startdate);
		if(user.getStr(User.column_stationids)!=null && !user.getStr(User.column_stationids).equals("7197dab3f7b04363b40d83886366bce2")){
			
			splitPage.getQueryParam().put("mangerIds",user.getStr( User.column_ids));
			json = paging(splitPage,DailyNursingTotal.sqlId_zblitPageSelect2,DailyNursingTotal.sqlId_zbsplitPageFrom2);
		}else{
			json = paging(splitPage,DailyNursingTotal.sqlId_zblitPageSelect,DailyNursingTotal.sqlId_zbsplitPageFrom);
		}
		//splitPage.getQueryParam().put("organids",  organids);
		
		renderJson(json);
		/*if(organization.getInt(Organization.column_level) == 4)//门店级别
		{	
			String sql = "SELECT sctd.*,so.name orgname,so.kyTime,TIMESTAMPDIFF(MONTH,so.kyTime,NOW( )) dl "+
						 " FROM sb_customer_total_daily  sctd  LEFT JOIN  sys_organization  so  ON sctd.organids = so.ids "+
						 " WHERE sctd.organids = ? AND  sctd.date= ? ";
			List<DailyNursingTotal>  dnt = DailyNursingTotal.dao.find(sql,organids,date);
			renderJson(dnt);
		}else if(organization.getInt(Organization.column_level) == 3)//代理商级别
		{
			splitPage.getQueryParam().put("date", date);
			splitPage.getQueryParam().put("organids",  organids);
			String json = paging(splitPage,DailyNursingTotal.sqlId_splitPageSelect,DailyNursingTotal.sqlId_splitPageFrom);
			renderJson(json);
		}else
		{
			renderJson("");
		}*/
	}
	
	
	
	public  void  getZbDailyTotalByDQJL()
	{
		String startdate  = getPara("_query.startdate");
		String lastdate  = getPara("_query.lastdate");
		splitPage.getQueryParam().put("lastdate", lastdate);
		splitPage.getQueryParam().put("startdate", startdate);
		String json = paging(splitPage,DailyNursingTotal.sqlId_zbDQJLlitPageSelect,DailyNursingTotal.sqlId_zbDQJLsplitPageFrom);
		
		renderJson(json);
		
	}
	
	public  void  tolookInfo()
	{
		
		String organids = getPara("organids");
		setAttr("organids", organids);
		render("zbDailyTotalInfo.html");
	
	}
	public  void  lookInfo()
	{
		String startdate  = getPara("_query.startdate");
		String lastdate  = getPara("_query.lastdate");
		String organids = getPara("_query.organIds");
		String json ="";
		Organization org = Organization.dao.findById(organids);
		splitPage.getQueryParam().put("lastdate", lastdate);
		splitPage.getQueryParam().put("startdate", startdate);
		
		if(org!=null){//区分传过来的是省份还是代理
			splitPage.getQueryParam().put("organids",  organids);
			if(org.getInt(Organization.column_level)==2){
				json = paging(splitPage,DailyNursingTotal.sqlId_zbinfolitPageSelect,DailyNursingTotal.sqlId_zbinfosplitPageFrom);
			}else if(org.getInt(Organization.column_level)==3){
				json = paging(splitPage,DailyNursingTotal.sqlId_splitPageSelect,DailyNursingTotal.sqlId_splitPageFrom);
			}
			
		}else{
			splitPage.getQueryParam().put("mangerIds",  organids);
			json = paging(splitPage,DailyNursingTotal.sqlId_zbinfolitPageSelect,DailyNursingTotal.sqlId_zbinfosplitPageFrom);
		}
		//Organization organization = Organization.dao.findById(organids);
		
		
		
		renderJson(json);
	
	}
}
